{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "using ODEInterface\n",
    "using Gadfly\n",
    "using Colors\n",
    "@ODEInterface.import_huge\n",
    "loadODESolvers();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "function threebody(t,x,dx)\n",
    "    with_bigfloat_precision(113) do\n",
    "        mu = parse(BigFloat,\"0.012277471\"); ms = 1 - mu;\n",
    "        r1 = vecnorm(x[1:2]-[-mu,0]);\n",
    "        r2 = vecnorm(x[1:2]-[ ms,0]);\n",
    "        dx[1] = x[3];\n",
    "        dx[2] = x[4];\n",
    "        dx[3] = x[1] + 2*x[4] - ms*(x[1]+mu)/r1^3 - mu*(x[1]-ms)/r2^3;\n",
    "        dx[4] = x[2] - 2*x[3] - ms*     x[2]/r1^3 - mu*     x[2]/r2^3;\n",
    "    \n",
    "        return nothing\n",
    "    end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "set_bigfloat_precision(113);\n",
    "opt=OptionsODE(OPT_EPS => 1.11e-16,OPT_RTOL => 1e-16,OPT_ATOL=>1e-16,OPT_RHS_CALLMODE => RHS_CALL_INSITU);\n",
    "\n",
    "t0 = 0.0; T = parse(BigFloat,\"17.0652165601579625588917206249\");\n",
    "x0=[0.994, 0.0, 0.0, parse(BigFloat,\"-2.00158510637908252240537862224\")];\n",
    "\n",
    "(t,x,retcode,stats) = odecall(dop853, threebody, [t0, T], x0, opt);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plotColors = [\"black\", \"#4d5991\", \"#4bdf8c\"];\n",
    "\n",
    "arenstorfPlot = plot(layer(x=x[:,1],y=x[:,2],Geom.point,\n",
    "Theme(default_point_size=2pt,default_color=parse(Colorant,plotColors[1])),order=1),\n",
    "layer(x=[0],y=[0],Geom.point,\n",
    "Theme(default_point_size=10pt,default_color=parse(Colorant,plotColors[2])),order=2),\n",
    "layer(x=[0.994],y=[0],Geom.point,\n",
    "Theme(default_point_size=8pt,default_color=parse(Colorant,plotColors[3])),order=2),\n",
    "Theme(major_label_font_size=30pt,panel_stroke=colorant\"black\",highlight_width=0.1pt,\n",
    "minor_label_font_size=28pt,key_title_font_size=30pt,key_label_font_size=24pt,key_position=:top,\n",
    "key_max_columns = 1),\n",
    "Coord.Cartesian(xmin=-1.4,xmax=1.1),Guide.xlabel(\"x\",orientation=:horizontal),\n",
    "Guide.manual_color_key(\"Legend\",[\"Spaceship\", \"Earth\", \"Moon\"],[\"black\", \"#4d5991\", \"#4bdf8c\"]))\n",
    "\n",
    "draw(SVGJS(30cm, 30cm), arenstorfPlot)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.4.2",
   "language": "julia",
   "name": "julia-0.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.4.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
